package com.topc.oj.runnable.time;

public class TimeRunnable implements Runnable{

    private final int time;

    private final Process process;

    public TimeRunnable(int time, Process process) {
        this.time = time;
        this.process = process;
    }


    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            if (process.isAlive()) process.destroy();
        }
    }
}
